/**
 * 系统程序入口
 */
Ext.onReady(function() {
	Ext.BLANK_IMAGE_URL = '././lib/extjs/resources/images/default/s.gif';
	Ext.QuickTips.init(); //为需要的元件提供提示信息功能
	Ext.form.Field.prototype.msgTarget = 'qtip';
	
	//var bool = init(); // 初始化
	/*if (!bool) {
		window.location.href = '';
	}*/
	
	Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); // 保存状态
	
	DC.obj.explorer_treePanel = new DC.front.ExplorerPanel(); // 项目视图列表
	
	var sysToolBar = new DC.front.SysToolBar(); // 系统菜单
	
	DC.obj.editor_tabPanel = new DC.front.EditorTabPanel(); //代码编辑窗口
	
	DC.obj.msg_tabPanel = new DC.front.MsgTabPanel(); //消息提示的tab窗口
	//<div id="header" class="x-small-editor"><div id="sys_menu"><a id="file" href="javascript:void(0);">File</a><a id="file" href="javascript:void(0);">Edit</a></div></div>
	var top_menu = '<div id="header">'
			+ '    <div style="float:left;" class="x-small-editor">'
			+ '	       <span class="logo_front">Day Code IDE</span>'
			+ '		   <ul class="menu">'
			+ '	           <li id="sys_menu_file"></li>'
			+ '	           <li id="sys_menu_edit"></li>'
			+ '	           <li id="sys_menu_project"></li>'
			+ '	           <li id="sys_menu_team"></li>'
			+ '		   </ul>'
			+ '    </div>' 
			+ '    <div style="float:right; margin-right:10px;">'
			+ '        <ul class="sys_opt">'
			+ '            <li class="sys_manager"><a href="javascript:void(0);" id="sys_top_sysManager">Setting</a></li>'
			+ '            <li class="logout"><a href="javascript:void(0);" id="sys_top_logout">Logout</a></li>'
			+ '        </ul>'
			+ '    </div>'
			+ '</div>';
	var viewport = new Ext.Viewport({
        layout:'border',
        items:[{
        	xtype : 'panel',
        	layout:'border',
			title: top_menu,
			region:'center',
			margins: '0 0 0 0',
			cmargins: '0 0 0 0',
			items: [sysToolBar, DC.obj.explorer_treePanel, {
				xtype : 'panel',
				layout: 'border',
				header: false,
				region: 'center',
				margins: '3 3 3 0',
				cmargins: '0 0 0 0',
				items: [ DC.obj.editor_tabPanel, {
					xtype : 'panel',
					id: 'msg_panel',
					title: '',
					layout: 'fit',
					margins: '-1 0 0 0',
					cmargins: '0 0 0 0',
					region: 'south',
					height: 200,
					split : true,
					header: false,
					items: [ DC.obj.msg_tabPanel ]
				}]
			}]
        }, {
        	xtype : 'panel',
        	header : false,
        	heigh : 25,
        	region : 'south',
        	html : '<div class="footer"><div class="path"><span id="status_bar_file_path">&nbsp;</span></div><div id="status_bar_progress" class="progress"></div></div>'
        }]
    });
   
    /* 创建系统菜单   */
   DC.front.CreateSysMenu();
   Ext.get("sys_top_logout").on("click", function() {
	   DC.action.SysAction.logout();
   });
   Ext.get("homepage_modify_userInfo_icon").on("click", function() {
	   new DC.front.win.ModifyUserInfoWin().show();
   });
   Ext.get("homepage_modify_password_icon").on("click", function() {
	   new DC.front.win.ModifyPasswordWin().show();
   });
   Ext.get('explorer_panel_collapse_all').on('click', function() {
	   DC.obj.explorer_treePanel.collapseAll();
   });
   Ext.get('explorer_panel_expand_all').on('click', function() {
	   DC.obj.explorer_treePanel.expandAll();
   });
  /*  Ext.get("sys_menu_file").on("mouseover", function() {
    	if (file_toolbar) {
    		if (this.child('a'))
    			this.child('a').remove();
    		file_toolbar.render('sys_menu_file');
    	}
    })*/
});

/**
 * 系统初始化
 */
function init() {
	var flag = true;
	Ext.Ajax.request({
	    url : DC.url.GET_CURRENTUSERINFO,
	    method : 'POST',
	    success : function(response, options){
		    var res = Ext.util.JSON.decode(response.responseText);
		    var obj = res.user;
		    console.log(obj);
		    DC.front.variable.SYS_CURRENTUSER.username = obj.username;
	    },
	    failure : function(response, options){
	    	flag = false;
	    }
    });
	
	return flag;
}